from sklearn.datasets import load_breast_cancer
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import train_test_split

cancer = load_breast_cancer()  # 乳腺癌数据集
# 数据集划分
X_train, X_test, y_train, y_test = train_test_split(
    cancer.data, cancer.target, test_size=0.2)

# 构建模型
model = LogisticRegression(max_iter=5000)  # 最大迭代次数 max_iter
model.fit(X_train, y_train)  # 训练模型

train_score = model.score(X_train, y_train)  # 训练得分
test_score = model.score(X_test, y_test)  # 预测得分

print(f'训练得分:{train_score:.4f}\n预测得分:{test_score:.4f}')
